/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ejemplo.DAO;

import com.ejemplo.TO.TerceroTO;
import com.ejemplo.entity.Tercero;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author CARLOS
 */
@Repository
public class TerceroDAO extends HibernateDaoSupport implements TerceroDAOInterface {
    @Autowired
    public TerceroDAO(SessionFactory sessionFactory){
        super.setSessionFactory(sessionFactory);
    }


    @Override
    public List<TerceroTO> getListaTercero() {
        Session session=getHibernateTemplate().getSessionFactory().openSession();
        
        Query consulta=session.createSQLQuery("select ruc as ruc, entidad as entidad, direcion as direcion, telefono as telefono from Tercero").
                setResultTransformer(Transformers.aliasToBean(TerceroTO.class));
        
    return consulta.list();
    }

    @Override
    public List<TerceroTO> getListaTercero2() {
        return this.getHibernateTemplate().find("select c from tercero c");
    }

    @Override
    public boolean insertarActualizaTercero(Tercero t) {
        boolean b=false;
        try{
            getHibernateTemplate().saveOrUpdate(t);
            b=true;
        }catch(Exception e){
            e.printStackTrace();
        }
        return b;
    }
    

   
}
